Option Explicit On 
Imports System.Xml
Imports System.Data

Public Class Class_SAP_BAPI

    Private Data_SAP As New Object

    Public Sub New()

        If Connect_SAP Then

            Dim Connector As New SAP.Connector.Destination

            Data_SAP = New SAP_BAPI.SAP_BAPI

            Connector.AppServerHost = "172.17.15.85"
            Connector.SystemNumber = 10
            Connector.Client = 100
            Connector.Username = "hrbapi"
            Connector.Password = "initall"

            Data_SAP.Connection = New SAP.Connector.SAPConnection(Connector)
            Data_SAP.Connection.Open()

        End If

    End Sub

    Protected Overrides Sub Finalize()

        MyBase.Finalize()

        Data_SAP.connection.close()

    End Sub

    Public Function SAP_Get_ZBAPI_BWHR_TEXT_COSTCENTER(Optional ByVal C0_Area As String = "", _
                                                       Optional ByVal Costcenter As String = "") As DataTable

        If Connect_SAP Then

            Dim BAP As New SAP_BAPI.BAPIRETURN
            Dim RetTable As New SAP_BAPI.ZBI0_TCOSTCENTERTable

            Data_SAP.Zbapi_Bwhr_Text_Costcenter(C0_Area, Costcenter, BAP, RetTable)
            SAP_Get_ZBAPI_BWHR_TEXT_COSTCENTER = RetTable.ToADODataTable()

            BAP = Nothing
            RetTable = Nothing
        Else
            'Dim Con As New Class_PTT_PIS
            'Dim DS As New DataSet
            'Dim StrSQL As String

            'If C0_Area = "" Then C0_Area = "%"
            'If Costcenter = "" Then Costcenter = "%"

            'StrSQL = "Select * from ZBAPI_BWHR_TEXT_COSTCENTER where "
            'StrSQL = StrSQL & " (C0_Area like '" & C0_Area & "')"
            'StrSQL = StrSQL & " and (Costcenter like '" & Costcenter & "')"

            'DS = Con.Get_Dataset(, , , , StrSQL)

            'If IsNothing(DS) Then
            '    SAP_Get_ZBAPI_BWHR_TEXT_COSTCENTER = Nothing
            'Else
            '    SAP_Get_ZBAPI_BWHR_TEXT_COSTCENTER = DS.Tables(0)
            'End If

            'Con = Nothing
            'DS = Nothing
            'StrSQL = Nothing

        End If

    End Function

    Public Function SAP_Get_ZBAPI_BWHR_TEXT_PERS_AREA(Optional ByVal Pers_Area As String = "") As DataTable

        If Connect_SAP Then

            Dim BAP As New SAP_BAPI.BAPIRETURN
            Dim RetTable As New SAP_BAPI.ZBI0_TPERS_AREATable

            Data_SAP.Zbapi_Bwhr_Text_Pers_Area(Pers_Area, BAP, RetTable)
            SAP_Get_ZBAPI_BWHR_TEXT_PERS_AREA = RetTable.ToADODataTable()

            BAP = Nothing
            RetTable = Nothing

        Else

            'Dim Con As New Class_Connection_SQL
            'Dim DS As New DataSet
            'Dim StrSQL As String

            'If Pers_Area = "" Then Pers_Area = "%"

            'StrSQL = "Select * from ZBAPI_BWHR_TEXT_PERS_AREA where "
            'StrSQL = StrSQL & " (Pers_Area like '" & Pers_Area & "')"

            'DS = Con.Get_Dataset(, , , , StrSQL)

            'If IsNothing(DS) Then
            '    SAP_Get_ZBAPI_BWHR_TEXT_PERS_AREA = Nothing
            'Else
            '    SAP_Get_ZBAPI_BWHR_TEXT_PERS_AREA = DS.Tables(0)
            'End If

            'Con = Nothing
            'DS = Nothing
            'StrSQL = Nothing

        End If

    End Function

End Class
